package com.itheima.zuoye.zy1;

public class MyRunnable implements Runnable {
    int num = 100;

    @Override
    public void run() {
        while (true) {
            if (sendGift()) {
                break;
            }
        }
    }

    public synchronized boolean sendGift() {
        if (num > 10) {
            System.out.println(Thread.currentThread().getName() + "，已发送" + num + "个礼物");
            num--;
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return false;
        } else {
            System.out.println(Thread.currentThread().getName() + "，没有礼物了");
            return true;
        }

    }
}

